package com.example.lvsuo.service.cxg.impl;

import com.example.lvsuo.entity.cxg.FlowName;
import com.example.lvsuo.entity.cxg.vo.FlowNameVo;
import com.example.lvsuo.mapper.cxg.FlowNameMapper;
import com.example.lvsuo.service.cxg.IFlowNameService;
import com.example.lvsuo.service.impl.SystemAuthorityServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class FlowNameServiceImpl implements IFlowNameService {

    @Autowired
    FlowNameMapper flowNameMapper;
    @Autowired
    SystemAuthorityServiceImpl authorityService;
    @Autowired
    IFlowLineServiceImpl iFlowLineService;


    @Override
    public String addFlownames(FlowName flowName) {
        flowNameMapper.addFlownames(flowName);
        return flowNameMapper.lastById();//添加成功后返回最新添加的主键
    }

    @Override
    public List<FlowName> getFlowName(FlowNameVo flowNameVo) {
        return flowNameMapper.getFlowName(flowNameVo);
    }

    @Override
    public void delFlowName(String fid) {
        flowNameMapper.delFlowName(fid); // 先删除flow_name
        iFlowLineService.delLineByFid(fid);// 再删除flow_line

    }

    @Override
    public FlowName getFlowNameByid(String id) {

        String systemAuthorityByid = authorityService.getSystemAuthorityByid(id);

        return flowNameMapper.getFlowNameByid(systemAuthorityByid);
    }
}
